home *** CD-ROM | disk | FTP | other *** search
/ DarkBASIC - The Ultimate 3D Game Creator / PCactive 8 CD1 - DarkBasic.iso / SOFTWARE / DEMOS / darkdrum / DarkDrum.dba < prev    next >
Encoding:
Text File  |  2001-01-19  |  12.1 KB  |  561 lines

  1. `=========================
  2. `Simple Drum Machine
  3. `   By Andrew Pye
  4. `    28/12/2000
  5. `andrew.pye@ukgateway.net
  6. `    Created With Dark Basic
  7. `      Simple Power
  8. `=========================
  9. restart:
  10. `===================
  11. `SET UP OUR VARIBLES
  12. `===================
  13. BANKS=9
  14. PATTSTEPS=16
  15. CHANNELS=8
  16. BPM=130
  17. CURRENTCHANNEL=1
  18. CURRENTBANK=1
  19. BAR=0
  20. SongLength=255
  21. Song_Bar=1
  22. Song_Pattern=1
  23. Song_Loop=1
  24.  
  25. `==========================
  26. `create our pattern storage
  27. `==========================
  28. dim PatternStore((PATTSTEPS*BANKS),CHANNELS)
  29.  
  30. `===============================
  31. `Create our storage for the song
  32. `===============================
  33. dim Song(SongLength-1)
  34. for i=0 to SongLength-1
  35.    song(i)=Song_Pattern
  36. next i
  37.  
  38. `==================
  39. `CREATE THE DISPLAY
  40. `==================
  41. set display mode 640,480,16
  42.  
  43. `==================================
  44. `LOAD IN THE SOUNDS FORTHE CHANNELS
  45. `==================================
  46. load sound "DRUMB.wav",1
  47. load sound "crashsymble.WAV",2
  48. load sound "HAT.wav",3
  49. load sound "lTom.WAV",4
  50. load sound "rimshot.WAV",5
  51. load sound "snare.WAV",6
  52. load sound "clap.WAV",7
  53. load sound "bass.wav",8
  54.  
  55. `==================
  56. `CREATE THE DIAPLAY
  57. `==================
  58. set display mode 640,480,16
  59. load bitmap "Keyboard.bmp",1
  60. load bitmap "Clear.bmp",2
  61.  
  62. SET CURRENT BITMAP 0
  63. COPY BITMAP 1,0
  64. set CURRENT BITMAP 0
  65.  
  66. `========================
  67. `MAKE SO IT DOES NOT PLAY
  68. `========================
  69. PLAYFLAG=0
  70. CURRENTBANK=1
  71. PLAYFLAG=0
  72.  
  73. `===============
  74. `gosub Drawlight
  75. `===============
  76. gosub UpdateDisplay
  77.  
  78. `======================================
  79. `this is to speed up the button display
  80. `======================================
  81. create bitmap 3,320,240
  82. load bitmap "buttons.bmp",3
  83. copy bitmap 3,0,0,319,239,0,200,210,520,450
  84. set CURRENT BITMAP 0
  85.  
  86.  
  87. `==============
  88. `store the time
  89. `==============
  90.  storetime=timer()
  91.  
  92. do
  93.    `=======================================
  94.    `Do a check to see if S has been pressed
  95.    `=======================================
  96.    `Save
  97.    if scancode()=31
  98.       GOSUB save
  99.       COPY BITMAP 1,0
  100.       set CURRENT BITMAP 0
  101.       copy bitmap 3,0,0,319,239,0,200,210,520,450
  102.       gosub UpdateDisplay
  103.       gosub Drawlight
  104.    endif
  105.    `lOAD
  106.    if scancode()=38
  107.       GOSUB load
  108.       COPY BITMAP 1,0
  109.       set CURRENT BITMAP 0
  110.       copy bitmap 3,0,0,319,239,0,200,210,520,450
  111.       gosub UpdateDisplay
  112.       gosub Drawlight
  113.    endif
  114.    `new
  115.  
  116.    if PLAYFLAG>0
  117.       if timer()=>storetime+(230-bpm)
  118.          `==============
  119.          `PLAY THE TRACK
  120.          `==============
  121.          TCount=(CHANNELS-1)
  122.          for i=0 to TCount
  123.              if  PatternStore(bar+(PATTSTEPS*(CURRENTBANK-1)),i)=1
  124.                 play sound (i+1)
  125.              endif
  126.          next i
  127.          `==========
  128.          `store time
  129.          `==========
  130.          storetime=timer()
  131.  
  132.          `==============
  133.          `CHECK THE BAR
  134.          `==============
  135.          IF BAR=15
  136.             BAR=0
  137.             `=========================
  138.             `THIS CREATES THE THE SONG
  139.             `=========================
  140.             IF PLAYFLAG=2
  141.                IF Song_Bar>=SongLength or Song_Bar>=Song_Loop
  142.                   Song_Bar=1
  143.                ELSE
  144.                   INC Song_Bar
  145.                ENDIF
  146.                   CURRENTBANK=SONG(Song_Bar-1)
  147.             ENDIF
  148.  
  149.          ELSE
  150.             INC BAR
  151.          ENDIF
  152.       ENDIF
  153.    ENDIF
  154.    if mouseclick()=1
  155.          `=======
  156.          `tempo +
  157.          `=======
  158.          if buttonid=3
  159.             if bpm<300
  160.                inc bpm
  161.                gosub UpdateDisplay
  162.             endif
  163.             buttonid=0
  164.          endif
  165.  
  166.          `=======
  167.          `tempo -
  168.          `=======
  169.          if buttonid=4
  170.             if bpm>100
  171.                dec bpm
  172.                gosub UpdateDisplay
  173.             endif
  174.             buttonid=0
  175.          endif
  176.    endif
  177.    `=======================================
  178.    `HERE WE CHECK FOR CONTROLS BEEN PRESSED
  179.    `=======================================
  180.    if MOUSECLICK()=0 then ButtonFlag=0
  181.    IF MOUSECLICK()=1
  182.       if ButtonFlag=0
  183.          ButtonFlag=1
  184.          ButtonID=buttonpress(mousex(),mousey())
  185.          `===========================
  186.          `now lets process the result
  187.          `===========================
  188.          `====
  189.          `play
  190.          `====
  191.          if buttonid=1 then PLAYFLAG=1
  192.  
  193.          `====
  194.          `stop
  195.          `====
  196.          if buttonid=2
  197.             PLAYFLAG=0
  198.             bar=0
  199.          endif
  200.  
  201.  
  202.  
  203.          `===============
  204.          `Pattern Buttons
  205.          `===============
  206.          if buttonid=5
  207.             `===========================================
  208.             `a frew maths to get the button been pressed
  209.             `===========================================
  210.             col = Int(mouseX() / 20) -9
  211.             row = Int(mousey() / 30) - 6
  212.             selchannel=row-1
  213.             gosub singlelight
  214.          endif
  215.  
  216.          `============
  217.          `bank buttons
  218.          `============
  219.          if buttonid>5 and buttonid<15
  220.             CURRENTBANK=buttonid-5
  221.             gosub Drawlight
  222.             gosub UpdateDisplay
  223.          endif
  224.  
  225.          `========
  226.          `song bar +
  227.          `========
  228.          if buttonid=15
  229.             if Song_Bar<255
  230.                inc Song_Bar
  231.                Song_Pattern=SONG(Song_Bar-1)
  232.                gosub UpdateDisplay
  233.             endif
  234.          endif
  235.  
  236.          `========
  237.          `song bar -
  238.          `========
  239.          if buttonid=16
  240.             if Song_Bar>1
  241.                dec Song_Bar
  242.                Song_Pattern=SONG(Song_Bar-1)
  243.                gosub UpdateDisplay
  244.             endif
  245.          endif
  246.  
  247.          `============
  248.          `SONG PATTER+
  249.          `============
  250.          if buttonid=17
  251.             if Song_Pattern<9
  252.                inc Song_Pattern
  253.                SONG(Song_Bar-1)=Song_Pattern
  254.                gosub UpdateDisplay
  255.             endif
  256.          endif
  257.  
  258.          `============
  259.          `SONG PATTER-
  260.          `============
  261.          if buttonid=18
  262.             if Song_Pattern>1
  263.                dec Song_Pattern
  264.                SONG(Song_Bar-1)=Song_Pattern
  265.                gosub UpdateDisplay
  266.             endif
  267.          endif
  268.  
  269.          `=========
  270.          `play song
  271.          `=========
  272.          if buttonid=19
  273.             Song_Bar=1
  274.             bar=0
  275.             PLAYFLAG=2
  276.             CURRENTBANK=SONG(Song_Bar-1)
  277.             gosub UpdateDisplay
  278.          endif
  279.          `======
  280.          `Loop +
  281.          `======
  282.          if buttonid=20
  283.             if Song_Pattern<255
  284.                inc song_loop
  285.                gosub UpdateDisplay
  286.             endif
  287.          endif
  288.  
  289.          `======
  290.          `Loop +
  291.          `======
  292.          if buttonid=21
  293.             if Song_Pattern>1
  294.                dec song_loop
  295.                gosub UpdateDisplay
  296.             endif
  297.          endif
  298.  
  299.       endif
  300.    endif
  301. loop
  302.  
  303. `=================
  304. `draw single light
  305. `=================
  306. singlelight:
  307.    if PatternStore((col-1)+(PATTSTEPS*(CURRENTBANK-1)),row-1)=1
  308.       PatternStore((col-1)+(PATTSTEPS*(CURRENTBANK-1)),row-1)=0
  309.       ink rgb(0,255,0),rgb(0,255,0)
  310.    else
  311.       PatternStore((col-1)+(PATTSTEPS*(CURRENTBANK-1)),row-1)=1
  312.       ink rgb(255,0,0),rgb(255,0,0)
  313.    endif
  314.    ypos#=217+(30*selchannel)
  315.    xpos#=((col-1)*20)+200
  316.    circle xpos#+11,ypos#,2
  317. return
  318.  
  319.  
  320. `==========
  321. `draw light
  322. `==========
  323. Drawlight:
  324.    copy bitmap 3,0,0,319,239,0,200,210,520,450
  325.    set CURRENT BITMAP 0
  326.    for j=0 to 7
  327.       for i=0 to 15
  328.  
  329.          if PatternStore(i+(PATTSTEPS*(CURRENTBANK-1)),j)=1
  330.             ink rgb(255,0,0),rgb(255,0,0)
  331.             xpos#=(i*20)+200
  332.             ypos=217+(30*j)
  333.             circle xpos#+11,ypos,2
  334.          endif
  335.  
  336.  
  337.  
  338.       next i
  339.    next j
  340.  
  341. return
  342.  
  343.  
  344. `============================================
  345. `This is where we redraw all the display info
  346. `============================================
  347. UpdateDisplay:
  348. `set the ink color
  349.    ink rgb(255,0,0),rgb(255,0,0)
  350. `clear the displays
  351.    `tempo
  352.    COPY BITMAP 2,0,0,58,29,0,80,45,138,74
  353.    `song bar
  354.    COPY BITMAP 2,0,0,58,29,0,480,75,538,104
  355.    `song pattern
  356.    COPY BITMAP 2,0,0,58,29,0,480,135,538,164
  357.    `Bank
  358.    COPY BITMAP 2,0,0,58,29,0,358,120,416,149
  359.    `Loop
  360.    `COPY BITMAP 2,0,0,58,29,0,580,135,638,164
  361.    COPY BITMAP 2,0,0,38,29,0,580,135,618,164
  362.  
  363. `Tempo
  364.    set cursor 91,53
  365.    print bpm
  366. `Bank
  367.    set cursor 375,130
  368.    print CURRENTBANK
  369. `song bar
  370.    set cursor 493,82
  371.    print Song_Bar
  372. `song pattern
  373.    set cursor 493,143
  374.    print Song_Pattern
  375. `Loop
  376.    set cursor 590,143
  377.    print Song_Loop
  378. return
  379.  
  380. `==========================================
  381. `this will check if button has been pressed
  382. `==========================================
  383. function buttonpress(x,y)
  384.    `================
  385.    `restore the data
  386.    `================
  387.    restore
  388.    `=========
  389.    `SCAN LOOP
  390.    `=========
  391.    result = 0
  392.    for i=1 to 21
  393.       read x1
  394.       read x2
  395.       read y1
  396.       read y2
  397.  
  398.       `===========================
  399.       `HAS THE BUTTON BEEN PRESSED
  400.       `===========================
  401.       if x>=x1 and x<=x2 and y>=y1 and y<=y2
  402.          `button pressed
  403.          result=i
  404.       endif
  405.    next i
  406.    `===========
  407.    `BUTTON DATA
  408.    `===========
  409.    `PLAY STOP
  410.    DATA 60,160,105,134
  411.    DATA 60,160,151,179
  412.    `tempo up down
  413.    data 160,180,46,59
  414.    data 160,180,60,73
  415.    `track1 buttons
  416.    data 200,520,210,450
  417.    `bank buttons 6
  418.    data 320,360,30,60
  419.    data 360,400,30,60
  420.    data 400,440,30,60
  421.  
  422.    data 320,360,60,90
  423.    data 360,400,60,90
  424.    data 400,440,60,90
  425.  
  426.    data 320,360,90,120
  427.    data 360,400,90,120
  428.    data 400,440,90,120
  429.    `song bits
  430.    data 460,480,75,90
  431.    data 460,480,90,105
  432.  
  433.    data 460,480,135,149
  434.    data 460,480,149,165
  435.  
  436.    data 560,620,75,105
  437.  
  438.    `loop
  439.    data 560,580,135,149
  440.    data 560,580,149,165
  441.  
  442. endfunction result
  443.  
  444. save:
  445. `=============
  446. `Save function
  447. `=============
  448.  
  449. ink rgb(155,155,155),rgb(0,0,0)
  450.  
  451. start:
  452. rem Clear the screen
  453. cls
  454.  
  455. rem List files within checklist
  456. perform checklist for files
  457. print "Files in directory:"
  458. for t=1 to checklist quantity()
  459.    tstr$=checklist string$(t)
  460.    if right$(tstr$,3)="DRM"
  461.       print checklist string$(t)
  462.    endif
  463. next t
  464.  
  465. print
  466.  
  467. input "Save: ",name$
  468.  
  469. cls
  470.  
  471.    if file exist(name$ +".DRM")=1
  472.       set cursor 220,200
  473.       input "Over write File (Y/N) " + name$ + " :",res$
  474.       if res$="Y" or res$="y"
  475.          delete file name$ +".DRM"
  476.       else
  477.          goto qend
  478.       endif
  479.    endif
  480.  
  481.    cls
  482.    set cursor 320,200
  483.    Print "Saveing..."
  484.    `=====================
  485.    `Open file for reading
  486.    `=====================
  487.       open to write 1,name$ +".DRM"
  488.  
  489.          for i=0 to 254
  490.             tbyte=song(i)
  491.             write byte 1,tbyte
  492.          next i
  493.          `save pattern
  494.          for i=0 to (16*9)
  495.             for j=0 to 8
  496.                write byte 1,PatternStore(i,j)
  497.             next j
  498.          next i
  499.          write byte 1,BPM
  500.          WRITE BYTE 1,Song_Loop
  501.    close file 1
  502. qend:
  503.  
  504. RETURN
  505.  
  506.  
  507. load:
  508. `=============
  509. `load function
  510. `=============
  511. ink rgb(155,155,155),rgb(0,0,0)
  512. start2:
  513. rem Clear the screen
  514. cls
  515. rem List files within checklist
  516. perform checklist for files
  517. print "Files in directory:"
  518. for t=1 to checklist quantity()
  519.    tstr$=checklist string$(t)
  520.    if right$(tstr$,3)="DRM"
  521.       print checklist string$(t)
  522.    endif
  523. next t
  524. print
  525. input "Load: ",name$
  526. cls
  527.  
  528. if file exist(name$ + ".drm")=1
  529.    set cursor 320,200
  530.    Print "Loading..."
  531.    `=====================
  532.    `Open file for reading
  533.    `=====================
  534.       open to read 1,name$ + ".DRM"
  535.  
  536.          for i=0 to 254
  537.             read BYTE 1,tbyte
  538.             song(i)= tbyte
  539.          next i
  540.          `save pattern
  541.          for i=0 to (16*9)
  542.             for j=0 to 8
  543.                read byte 1,tbyte
  544.                PatternStore(i,j)=tbyte
  545.             next j
  546.          next i
  547.  
  548.          read byte 1,BPM
  549.          read byte 1,Song_Loop
  550.    close file 1
  551. else
  552.    set cursor 220,200
  553.    Print "Error Canno't Find File " + name$
  554.    set cursor 220,220
  555.    Print "Press Key To Continue..."
  556.    suspend for key
  557.   ` goto start2
  558. endif
  559.  
  560. RETURN
  561.